<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>第一个</button>
    <button>第二个</button>
    <button>第三个</button>

    <script>
        //1.页面上有三个按钮，编码实现单击按钮，分别显示按钮在元素数组中的下标
        var buttons = document.querySelectorAll('button');
        //var 声明的i是全局变量，打印时输出3
        //let 声明的i是块作用域
        for (let i = 0; i < buttons.length; i++) {
            buttons[i].onclick = function () {
                console.log(i);
            }
        }

        //2.使用解构赋值交换两个变量的值
        var a = 1, b = 2;
        [a, b] = [b, a];
        console.log('a=' + a, 'b=' + b);



        function push(arr, ...items) {
            items.forEach(function (item) {
                arr.push(item);
                console.log(item);
            })
        }
        var a = [1, 2];
        push(a, 1, 2, 3);



        const headtail = (head, ...tail) => { return [head, tail] }
        console.log(headtail(6, 2, 3, 4, 5));  //[6,[2,3,4,5]]
    </script>
</body>

</html>